# -*- mode: python ; coding: utf-8 -*-
from PyInstaller.utils.hooks import collect_all
import os

# 收集 numpy 和 pandas 的依赖
datas = []
binaries = []
hiddenimports = []

for pkg in ('numpy', 'pandas'):
    pkg_datas, pkg_binaries, pkg_hiddenimports = collect_all(pkg)
    datas += pkg_datas
    binaries += pkg_binaries
    hiddenimports += pkg_hiddenimports

# 添加 UI 文件夹作为顶级目录
ui_files = [
    ('UI/img4-1080.png', '.'),
    ('UI/img2-1080.png', '.'),
    ('UI/logo002.png', '.'),
    ('UI/logo1.png', '.'),
    ('UI/logo4.png', '.'),
    ('UI/logo5.png', '.'),
]

a = Analysis(
    ['main.py'],
    pathex=[],
    binaries=binaries,
    datas=datas + [
        ('data/MPN-IPN.xlsx', 'data'),
        ('data/DataChange.xlsx', 'data'),
        ('data/file_path.json', 'data'),
    ] + ui_files,  # 将 UI 文件添加到顶级目录
    hiddenimports=hiddenimports,
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    noarchive=False,
)

pyz = PYZ(a.pure)

# 创建 EXE 对象
exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.datas,
    [],
    name='main-v2.2.1',  # 注意：这里只指定文件名，不包含路径
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    upx_exclude=[],
    runtime_tmpdir=None,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
    icon=os.path.join('UI', 'icon002.ico'),  # 使用 os.path.join 确保路径正确
)

# 添加 COLLECT 步骤 - 这是文件夹模式的关键
coll = COLLECT(
    exe,  # 包含 EXE 对象
    a.binaries,
    a.datas,
    a.zipfiles,
    a.pure,
    name='dist',  # 输出到 dist 文件夹
    strip=False,
    upx=True,
    upx_exclude=[],
    append_pkg=False,
    cdict=None,
)